package com.itheima.aop;


import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

@Component
@Aspect
public class DataAdvice {

    @Pointcut("execution(boolean  com.itheima.service.*Service.*(*,*))")
    public void  pt(){}

    @Around("pt()")
    public Object trimStr(ProceedingJoinPoint pjp) throws Throwable {
        //获取目标方法的参数
        Object[] args = pjp.getArgs();
        for (int i = 0; i < args.length; i++) {
            //判断参数是不是字符串
            if(args[i].getClass().equals(String.class)){
                args[i] = args[i].toString().trim();
            }
        }
        //指定目标方法
        Object ret = pjp.proceed(args);
        return ret;
    }
}
